Skip to content

[LWDM] feat(coin-near): add CoinModuleApi for native NEAR and staking - #20296

Open
pawell24 wants to merge 1 commit into
developfrom
feat/LIVE-34284-near-coinmodule-api-migration
Open

[LWDM] feat(coin-near): add CoinModuleApi for native NEAR and staking#20296
pawell24 wants to merge 1 commit into
developfrom
feat/LIVE-34284-near-coinmodule-api-migration

Conversation

@pawell24

@pawell24 pawell24 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

📝 Description

Exposes the CoinModuleApi surface for NEAR alongside the existing account bridge, covering the
native asset and delegated staking (stake / unstake / withdraw).

The generic-framework flag stays off, so Ledger Live keeps routing NEAR through the account bridge
and user-facing behaviour is unchanged. Enabling it needs UI work on the NEAR screens and lands
separately.

The account bridge and the new surface now share their logic rather than duplicating it:

  • logic/fees.ts holds the fee formula, used by both getFeesForTransaction and estimateFees.
  • logic/actions.ts holds the action builder, used by both buildTransaction and
    craftTransaction.
  • network/protocolConfig.ts derives gas and storage costs from the protocol config behind a
    30-minute cache. The new path has no preload step, and the preload defaults are zeros, so
    sourcing costs from them would have produced a zero fee.

src/api/ moved to src/network/, since src/api/index.ts is now the module factory.

Scope: the ticket AC also lists tokens. NEAR has no NEP-141 support anywhere in Ledger Live,
including the account bridge, so there is nothing to migrate. Adding it is separate work.

Testing: 213 unit tests, including 7 that assert the crafted transaction is byte-identical to
the account bridge's, plus 40 integration tests against mainnet. Both paths were also exercised
manually in Ledger Live Desktop (balances, history, fees, validation, send-max, device signing and
a staking broadcast on mainnet); the values matched the account bridge to 8 decimals.

Enabling the framework for NEAR also needs a one-line fix in
generic-coin-framework/utils.ts, where an optimistic operation's fee is converted with
toString() instead of toFixed(). BigNumber switches to exponential notation from 1e21 up and
BigInt cannot parse it, which a NEAR staking fee (24 decimals) reaches at 0.0015. It is not
specific to NEAR, so it ships on its own.

🔗 Context

  • JIRA / GitHub issue: LIVE-34284
  • ADR (if any): n/a

Copilot AI review requested due to automatic review settings August 1, 2026 15:51
@live-github-bot live-github-bot Bot added common Has changes in live-common coin-modules-api Has changes in the coin-framework/coin-modules APIs coin-modules labels Aug 1, 2026
@live-github-bot live-github-bot Bot changed the title feat(coin-near): add CoinModuleApi for native NEAR and staking [LWDM] feat(coin-near): add CoinModuleApi for native NEAR and staking Aug 1, 2026
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Web Tools Build Status

Build Status Deployment
Web Tools Build ✅ Deployed https://web-tools-5dbdjtm39-ledger-hq-prd.vercel.app
Native Storybook Build ⏭️ Skipped
React Storybook Build ⏭️ Skipped

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a CoinModuleApi (“Alpaca”) implementation for the NEAR coin-module (native + delegated staking) while keeping Ledger Live’s current NEAR routing on the legacy account bridge. To avoid duplicated behavior, shared transaction/fee logic is refactored into reusable logic/* helpers and protocol-config–derived costs are introduced behind an LRU cache for non-preload call paths.

Changes:

  • Expose NEAR CoinModuleApi (balance, history, fees, crafting, staking reads) and wire it into live-common coin-module loaders.
  • Refactor shared fee formula + action building so both the bridge path and the CoinModuleApi path use the same logic.
  • Move NEAR “api” networking to src/network/* and add unit + integration coverage for indexer/node/protocol config.

Reviewed changes

Copilot reviewed 54 out of 59 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
libs/ledger-live-common/src/families/near/coinModuleApi.ts Adds local CoinModuleApi factory wiring for NEAR.
libs/ledger-live-common/src/families/near/banner.test.ts Consolidates NEAR type imports.
libs/ledger-live-common/src/coin-modules/loaders.ts Registers loadLocalApi for NEAR.
libs/ledger-live-common/.unimportedrc.json Adds near coinModuleApi to unimported ignore list.
libs/coin-modules/coin-near/src/types.ts Updates staking position type re-export to network/.
libs/coin-modules/coin-near/src/test/coinConfig.ts Adds helper to set mocked infra endpoints.
libs/coin-modules/coin-near/src/synchronisation.ts Switches sync imports from api to network.
libs/coin-modules/coin-near/src/preload.ts Preload derives costs via cached protocol config + constants.
libs/coin-modules/coin-near/src/network/sdk.types.ts Adds block header type for JSON-RPC block reads.
libs/coin-modules/coin-near/src/network/protocolConfig.ts Adds cached derivation of storage/gas action costs.
libs/coin-modules/coin-near/src/network/protocolConfig.test.ts Tests protocol-config cost derivation + caching.
libs/coin-modules/coin-near/src/network/node.ts Implements RPC/indexer-backed node calls (account, gas, broadcast, staking, validators).
libs/coin-modules/coin-near/src/network/node.test.ts Unit tests for node/indexer-backed calls.
libs/coin-modules/coin-near/src/network/node.mock.ts MSW server + mocked NEAR base URL.
libs/coin-modules/coin-near/src/network/indexer.ts Adds paged tx fetch and exports operation-type mapper.
libs/coin-modules/coin-near/src/network/indexer.test.ts Tests operation mapping resilience and paging envelope behavior.
libs/coin-modules/coin-near/src/network/indexer.integ.test.ts Mainnet integration tests for indexer-backed reads.
libs/coin-modules/coin-near/src/network/index.ts Barrel export for network layer APIs.
libs/coin-modules/coin-near/src/network/getBlock.ts Adds JSON-RPC block-header reads.
libs/coin-modules/coin-near/src/network/getBlock.test.ts Tests block-header reads + invalid height handling.
libs/coin-modules/coin-near/src/logic/transaction/validateIntent.ts Implements intent validation mirroring bridge behavior.
libs/coin-modules/coin-near/src/logic/transaction/validateIntent.test.ts Unit tests for transfer + staking validation rules.
libs/coin-modules/coin-near/src/logic/transaction/estimateFees.ts Implements fee estimation using protocol-config–derived costs.
libs/coin-modules/coin-near/src/logic/transaction/estimateFees.test.ts Unit tests for fee estimation and gasPrice overrides.
libs/coin-modules/coin-near/src/logic/transaction/craftTransaction.ts Crafts unsigned NEAR tx bytes for the framework path.
libs/coin-modules/coin-near/src/logic/transaction/craftTransaction.test.ts Unit tests for crafting, staking target resolution, access-key handling.
libs/coin-modules/coin-near/src/logic/transaction/craftTransaction.parity.test.ts Ensures byte parity with legacy buildTransaction.
libs/coin-modules/coin-near/src/logic/transaction/combine.ts Combines crafted tx + signature into signed tx bytes.
libs/coin-modules/coin-near/src/logic/transaction/combine.test.ts Unit tests for combine + signature validation.
libs/coin-modules/coin-near/src/logic/transaction/broadcast.ts Framework broadcast wrapper around network broadcast.
libs/coin-modules/coin-near/src/logic/transaction/broadcast.test.ts Unit tests for broadcast wrapper behavior.
libs/coin-modules/coin-near/src/logic/staking/getValidators.ts Maps indexer validators to framework Validator page.
libs/coin-modules/coin-near/src/logic/staking/getValidators.test.ts Unit tests for validator mapping and request size.
libs/coin-modules/coin-near/src/logic/staking/getStakes.ts Maps staking positions to framework Stake entries.
libs/coin-modules/coin-near/src/logic/staking/getStakes.test.ts Unit tests for stake bucketing and thresholds.
libs/coin-modules/coin-near/src/logic/history/listOperations.ts Implements paginated operations for framework path.
libs/coin-modules/coin-near/src/logic/history/listOperations.test.ts Unit tests for operation mapping + paging rules.
libs/coin-modules/coin-near/src/logic/history/lastBlock.ts Implements latest final block metadata.
libs/coin-modules/coin-near/src/logic/history/getBlockInfo.ts Implements block metadata lookup and conversion.
libs/coin-modules/coin-near/src/logic/history/getBlockInfo.test.ts Unit tests for block info conversion and reads.
libs/coin-modules/coin-near/src/logic/fees.ts Centralizes fee formula for bridge + framework paths.
libs/coin-modules/coin-near/src/logic/fees.test.ts Unit tests for fee computation modes and implicit accounts.
libs/coin-modules/coin-near/src/logic/actions.ts Centralizes NEAR action building for bridge + framework paths.
libs/coin-modules/coin-near/src/logic/actions.test.ts Unit tests for action building per mode.
libs/coin-modules/coin-near/src/logic/account/getBalance.ts Implements framework balances (native + staking positions).
libs/coin-modules/coin-near/src/logic/account/getBalance.test.ts Unit tests for balance ordering and locked computation.
libs/coin-modules/coin-near/src/logic.ts Generalizes staking gas inputs to not require bridge Transaction.
libs/coin-modules/coin-near/src/getTransactionStatus.ts Switches to network for account lookup.
libs/coin-modules/coin-near/src/getTransactionStatus.test.ts Updates MSW mock import path for node mocking.
libs/coin-modules/coin-near/src/getFeesForTransaction.ts Uses shared computeFees + new network/node gas price.
libs/coin-modules/coin-near/src/constants.ts Adds VALIDATORS_COUNT constant.
libs/coin-modules/coin-near/src/buildTransaction.ts Refactors legacy bridge building to reuse buildActions.
libs/coin-modules/coin-near/src/broadcast.ts Switches legacy broadcast import to network.
libs/coin-modules/coin-near/src/api/parity.integ.test.ts Mainnet parity tests between bridge and CoinModuleApi.
libs/coin-modules/coin-near/src/api/index.ts Implements NEAR CoinModuleApi entry point.
libs/coin-modules/coin-near/src/api/index.test.ts Unit tests that API delegates to logic implementations.
libs/coin-modules/coin-near/src/api/index.integ.test.ts Mainnet integration coverage for CoinModuleApi surface.
libs/coin-modules/coin-near/.unimportedrc.json Updates entrypoints/ignored files after api→network move.
.changeset/near-coinmodule-api.md Adds changeset for coin-near + live-common minor bumps.

Comment thread libs/coin-modules/coin-near/src/api/parity.integ.test.ts Outdated
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 7 projects in monorepo, 7 projects with changes.

📊 Quick Summary
Project Total Size Change
desktop-main 2.3 MB -
desktop-preloader 7.1 KB -
desktop-renderer 80.7 MB -
desktop-webviewDappPreloader 36.9 KB -
desktop-webviewPreloader 200.0 B -
desktop-workers 36.8 KB -
mobile 261.5 MB -
📋 Detailed Reports (Click to expand)

📁 desktop-main

Path: rsdoctor/desktop-main/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 2.3 MB - -
📄 JavaScript 2.2 MB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 135.3 KB - -

📁 desktop-preloader

Path: rsdoctor/desktop-preloader/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 7.1 KB - -
📄 JavaScript 5.3 KB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 1.8 KB - -

📁 desktop-renderer

Path: rsdoctor/desktop-renderer/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 80.7 MB - -
📄 JavaScript 29.3 MB - -
🎨 CSS 183.1 KB - -
🌐 HTML 1.8 KB - -
📁 Other Assets 51.2 MB - -

📁 desktop-webviewDappPreloader

Path: rsdoctor/desktop-webviewDappPreloader/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 36.9 KB - -
📄 JavaScript 36.9 KB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 desktop-webviewPreloader

Path: rsdoctor/desktop-webviewPreloader/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 200.0 B - -
📄 JavaScript 200.0 B - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 desktop-workers

Path: rsdoctor/desktop-workers/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 36.8 KB - -
📄 JavaScript 36.8 KB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 mobile

Path: rsdoctor/mobile/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 261.5 MB - -
📄 JavaScript 110.5 MB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 151.0 MB - -

Generated by Rsdoctor GitHub Action

Copilot AI review requested due to automatic review settings August 1, 2026 16:03
@pawell24
pawell24 force-pushed the feat/LIVE-34284-near-coinmodule-api-migration branch from 48c4f52 to 952f357 Compare August 1, 2026 16:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 54 out of 59 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings August 2, 2026 09:47
@pawell24
pawell24 force-pushed the feat/LIVE-34284-near-coinmodule-api-migration branch from 952f357 to cc9d58f Compare August 2, 2026 09:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 55 out of 60 changed files in this pull request and generated no new comments.

Suppressed comments (1)

libs/coin-modules/coin-near/src/logic/history/listOperations.ts:28

  • block_timestamp is a nanosecond timestamp encoded as a string and can exceed JS safe integer precision. Using Number.parseFloat(...) may introduce rounding drift. Converting via BigInt keeps the millisecond value exact and avoids precision loss.
export function toOperation(transaction: NearTransaction, address: string): Operation {
  const type = getOperationType(transaction, address);
  const date = new Date(Number.parseFloat(transaction.block_timestamp) / 1e6);

@sonarqubecloud

sonarqubecloud Bot commented Aug 2, 2026

Copy link
Copy Markdown

@pawell24
pawell24 marked this pull request as ready for review August 2, 2026 10:28
@pawell24
pawell24 requested a review from a team August 2, 2026 10:28
@pawell24
pawell24 requested review from a team as code owners August 2, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coin-modules coin-modules-api Has changes in the coin-framework/coin-modules APIs common Has changes in live-common

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants